﻿<template>
    <el-dialog
        :title="titleMap[mode]"
        v-model="visible"
        :width="1000"
        destroy-on-close
        @closed="$emit('closed')"
    >
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            label-width="100px"
        >
            <el-row>
                <el-col :span="12">
                    <el-form-item label-width="120px" label="物流名称" prop="supplierName">
                        <el-input v-model="entityObj.logisticsName"  />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label-width="120px" label="联系人" prop="realName">
                        <el-input v-model="entityObj.realName" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label-width="120px" label="手机号" prop="mobile">
                        <el-input v-model="entityObj.mobile"  />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label-width="120px" label="联系地址" prop="address">
                        <el-input v-model="entityObj.address"  />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label-width="120px" label="状态">
                        <el-switch v-model="entityObj.status" :active-value="1" :inactive-value="0" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="备注" >
                        <el-input v-model="entityObj.remarks" type="textarea" :rows="2"/>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button
                v-if="mode != 'show'"
                type="primary"
                :loading="isSaveing"
                @click="submit()"
            >保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
import tool from "@/utils/tool";
export default {
    emits: ["success", "closed"],
    data() {
        return {
            mode: "Add",
            titleMap: {
                Add: "新增",
                Edit: "编辑",
                Show: "查看",
            },
			entityObj:{
				status : 1
			},
            visible: false,
            isSaveing: false,
            needSaveFlag: false,
            //验证规则
            rules: {
                logisticsName: [{ required: true, type: "string", message: "请填写" }],
                realName: [{ required: true, type: "string", message: "请填写" }],
				mobile: [{ required: true, type: "string", message: "请填写" }],
				address: [{ required: true, type: "string", message: "请填写" }]
            },
        };
    },
    methods: {
        //显示=
        open(mode = "Add") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        //表单提交方法
        submit() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    try {
                        var returnValue = await this.$API.auth.PostProcessApi.post(this.mode == "Add"?"logistics/create":"logistics/update",{...this.entityObj});
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.$message.error(
                                "操作失败:" + returnValue.msg
                            );
                        }
                    } catch (error) {
                        this.loading = false;
                        return false;
                    }
                }
            });
        },
        //表单注入数据
        async setData(data) {
			this.entityObj={...data,status:data.status};
        },
    },
    async mounted() {
		this.entityObj.orgName=tool.data.get("USER_INFO").OrgName;
        //await this.initOptions();
    },
};
</script>

<style></style>
